package com.foton.lotterydomain.support.ids;

import com.foton.lotterycommon.common.Constants;
import com.foton.lotterydomain.support.ids.policy.RandomNumeric;
import com.foton.lotterydomain.support.ids.policy.ShortCode;
import com.foton.lotterydomain.support.ids.policy.SnowFlake;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author RenPu
 * @Date 2023/12/2 16:44
 * @Version 1.0
 * @Description: ID策略的上下文
 **/

@Configuration
public class IdContext {


    /**
     * 通过构造方法，进行将bean实例封装到Map中
     *
     * @param randomNumeric
     * @param shortCode
     * @param snowFlake
     * @return
     */
    @Bean("idsIdGeneratorMap")
    public Map<Constants.Ids, IdGenerator> getIdGenerator(RandomNumeric randomNumeric, ShortCode shortCode, SnowFlake snowFlake) {
        Map<Constants.Ids, IdGenerator> idsIdGeneratorMap = new ConcurrentHashMap<>(8);
        idsIdGeneratorMap.put(Constants.Ids.RandomNumeric, randomNumeric);
        idsIdGeneratorMap.put(Constants.Ids.ShortCode, shortCode);
        idsIdGeneratorMap.put(Constants.Ids.SnowFlake, snowFlake);
        return idsIdGeneratorMap;
    }

}
